﻿//
// Created by work on 24-6-6.
//

#ifndef IOT_PLAT_CRTMODELSIGBASE_H
#define IOT_PLAT_CRTMODELSIGBASE_H

#include <shlib/viewmodel/imodel.h>
#include <shlib/CValue.h>


class CRtModelSigBase : public IModel{
    Q_OBJECT
public:
    enum ESigType {
        EYx,
        EYc,
        EYk,
        EParameter
    };

    enum EBaseSigCol {
        EModel_name,
        EUser,
        EName,
        EDescr,
        ESn,
        EGrouping,
        EConfigs
    };

    QString model_name;
    QString user;
    QString name;
    QString descr;
    int sn = 1;
    QString grouping;
    QJsonObject configs;

    static std::map<CRtModelSigBase::EBaseSigCol, QString> baseSigColToStringMap;
    static std::map<CRtModelSigBase::EBaseSigCol, CValue::EValueType> baseSigDataTypeByField;
    static std::map<EBaseSigCol, QString> baseColFieldsNameMap;
    static std::map<QString, EBaseSigCol> nameToFieldsColMap;

public:
    explicit CRtModelSigBase(int colsize, QObject *parent = nullptr);
public:
    virtual QString getFieldNameByCol(int col)override;

    virtual QVariant getFieldValueByFielddName(const QString& name)override;

    virtual void setFieldValueByCol(int col, const QVariant& value)override;

    virtual QJsonObject toJson()override;

    virtual void fromJson(const QJsonObject &obj)override;

    virtual QSharedPointer<IModel> createEmpty()override;
};

#define BASE_SIG_ENUM                   CRtModelSigBase::EBaseSigCol
#define baseSigFieldName(type)          CRtModelSigBase::baseSigColToStringMap.find(type)->second
#define baseSigColFieldName(type)       CRtModelSigBase::baseColFieldsNameMap.find(type)->second
#define baseSigFieldType(type)          CRtModelSigBase::baseSigDataTypeByField.find(type)->second
#define SIGBASE_COL_SIZE                baseSigColToStringMap.size()


#endif //IOT_PLAT_CRTMODELSIGBASE_H
